package com.lijin.study.java.freemarker;

import java.io.File;
import java.io.FileWriter;
import java.util.HashMap;
import java.util.Map;

import org.junit.Test;

import freemarker.cache.FileTemplateLoader;
import freemarker.template.Configuration;
import freemarker.template.Template;

public class TemplateTest {

	private Configuration cfg;
	
	private void init() throws Exception {
		cfg = new Configuration();
		cfg.setTemplateLoader(new FileTemplateLoader(new File("D:\\workspace\\study-java\\src\\main\\resources\\freemarker\\template")));
	}
	
	@Test
	public void test1() throws Exception {
		init();
		
		Map<String, Object> root = new HashMap<String, Object>();
        root.put("message", "Hello World!");
        root.put("message1", "Hello World1!");
        root.put("message2", "Hello World2!");
        root.put("message3", "Hello World3!");
		
        Template t = cfg.getTemplate("test.ftl");
        t.process(root, new FileWriter(new File("D:\\Target.html")));
	}
}
